<?php $this -> load -> view('adminx/header'); ?>
<!-- BEGIN CONTAINER -->
<div class="page-container">
    <!-- BEGIN SIDEBAR -->
    <?php $this -> load -> view('adminx/mune'); ?>
    <!-- END SIDEBAR -->
    <!-- BEGIN CONTENT -->
    <div class="page-content-wrapper">
        <div class="page-content">
            <!-- BEGIN SAMPLE PORTLET CONFIGURATION MODAL FORM-->
            <!-- /.modal -->
            <h3 class="page-title"> <?php echo $title; ?> <small><?php echo $en; ?></small></h3>
            <div class="page-bar">
                <ul class="page-breadcrumb">
                    <li>
                        <i class="fa fa-home"></i>
                        <a href="/adminx">首页</a>
                        <i class="fa fa-angle-right"></i>
                    </li>
                    <li>
                        <a href="/iadmin/team"><?php echo $title; ?></a>
                        <i class="fa fa-angle-right"></i>
                    </li>
                    <li>
                        <a href="#">查看<?php echo $title; ?></a>
                    </li>
                </ul>
            </div>
            <!-- END PAGE HEADER-->
            <div class="clearfix"></div>
            <div class="row">
                <div class="col-lg-12 col-md-12">
                    <div class="portlet light ">
                        <div class="portlet-title">
                            <div class="caption">
                                <i class="icon-share font-red-sunglo"></i>
                                <span class="caption-subject font-red-sunglo bold uppercase"><?php echo $title; ?>管理</span>
                            </div>
                            <div class="actions">
                                <a class="btn btn-circle btn-icon-only blue" href="javascript:;" onclick="alert_ts('<?php echo $this -> config -> item('xt_ts'); ?>')"> <i class=" icon-bulb"></i> </a>
                                <a class="btn btn-circle btn-icon-only btn-default fullscreen" href="javascript:;"> </a>
                            </div>
                        </div>
                        <div class="portlet-body">
                            <div class="btn-toolbar margin-bottom-10">
                                <form class="btn-toolbar" id="get_tbody" onkeydown="if(event.keyCode==13)return false;">
                                    <div class="portlet-input input-inline" style="margin-left: 10px;width: 150px;">
                                        <div class="input-icon right">
                                            <i class="icon-magnifier"></i>
                                            <input id="key" name="key" type="text" class="form-control" placeholder="search...">
                                        </div>
                                    </div>
                                    <div class="portlet-input input-inline">
                                        <select  id="page" name="page" class="form-control input-circle" style="width: 100px;">
                                            <option>1</option>
                                        </select>
                                    </div>
                                    <a class="btn purple" href="/iadmin/team/add"><i class="fa  fa-pencil"></i> 添加<?php echo $title; ?></a>
                                </form>
                            </div>
                            <div class=""></div>
                            <div class="table-scrollable">
                                <table class="table table-bordered table-hover">
                                    <thead>
                                    <tr>
                                        <th>#</th>
                                        <th>名称</th>
                                        <th>头像</th>
                                        <th>队长</th>
                                        <th >业绩</th>
                                        <th>排名</th>
                                        <th style="width: 330px;" >操作</th>
                                    </tr>
                                    </thead>
                                    <tbody id="tbody">
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- BEGIN QUICK SIDEBAR -->
    <?php $this -> load -> view('adminx/lt'); ?>
    <!-- END QUICK SIDEBAR -->
</div>

<script type="text/html" id="list_tpl">
    <tr>
        <td>{team_id}</td>
        <td>{name}</td>
        <td><img width="120" src="{head_image}" /></td>
        <td>{nickname}</td>
        <td>{achievement}</td>
        <td>{rank}</td>
        <td>
            <a href="/iadmin/team/up/{team_id}" type="button" class="btn green"><i class="fa fa-edit"></i> 修改</a>
            <button onclick="del('{team_id}','{name}')" type="button" class="btn red"><i class="fa fa-trash-o"></i> 删除</button>
        </td>
    </tr>
</script>

<?php $this -> load -> view('adminx/footer'); ?>
<link href="/mex/global/plugins/uk/themes/default/css/umeditor.css" type="text/css" rel="stylesheet">
<script type="text/javascript" charset="utf-8" src="/mex/global/plugins/uk/umeditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/mex/global/plugins/uk/umeditor.min.js"></script>
<script type="text/javascript" src="/mex/global/plugins/uk/lang/zh-cn/zh-cn.js"></script>

<script src="/mex/global/plugins/ajaxfileupload.js"></script>

<script>
    $(function () {
        getTeam()
            .done(function (result) {
                var len = result.length,
                    $renderCon = $('#tbody'),
                    tpl = $('#list_tpl').html();
                for (var i = 0; i < len; i++) {
                    $renderCon.append(render(result[i], tpl));
                }
                console.log(render(result[0], 'list_tpl'));
            });
    });
    function render (data, tpl) {
        for(var key in data) {
            var result = data[key];
            tpl = tpl.replace(new RegExp('{' + key + '}',"g"), result);
        }
        return tpl;
    }
    function getTeam (key, page) {
        return $.ajax({
            type : "post",
            url : "/iadmin/team/get",
            dataType : "json",
            data : {
                key : key || '',
                page : page || 1
            }
        });
    }
    function del(_idx, _content) {
        var _model = 'team';
        bootbox.dialog({
            message : "是否删除 <span class=\"label label-success\">" + _content + "</span> ?",
            title : "删除提示",
            buttons : {
                success : {
                    label : "<i class=\"fa  fa-compress\"></i> 关闭",
                    className : "default",
                    callback : function() {
                    }
                },
                danger : {
                    label : "<i class=\"fa fa-send\"></i> 删除",
                    className : "red",
                    callback : function() {
                        $.ajax({
                            type : "post",
                            url : "/iadmin/" + _model + "/del",
                            dataType : "json",
                            data : {
                                idx : _idx
                            },
                            success : function(msg) {
                                if (msg.type == 1) {
                                    get_tbody(_model);
                                    alert_ts('删除成功！');
                                } else {
                                    alert_ts('抱歉，删除失败！');
                                }
                            }
                        });
                    }
                }
            }
        });
    }
</script>